﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.DynamicProxy;
using System.Linq.Expressions;
using System.Reflection;

namespace JackyCode.Mock
{
    public class Mock<TEntity> where TEntity:class
    {
        private object mockObject;

        private ProxyGenerator proxyGenerator = new ProxyGenerator();

        public IMockObjectFactory<TEntity> MockObjectFactory {get;set;}

        public Mock() : this(new MockObjectFactoryImpl<TEntity>()) { }

        public Mock(IMockObjectFactory<TEntity> mockObjectFactory) 
        {
            if (mockObjectFactory == null)
            {
                throw new ArgumentNullException("The [MockFactory] argument can't be null!");
            }
            this.MockObjectFactory = mockObjectFactory;
        }

        public object Object
        {
            get
            {
                if (mockObject == null)
                {
                    mockObject = MockObjectFactory.CreateObject();
                }
                return mockObject;
            }
        }

        public ISetUp<TResult> SetUp<TResult>(Expression<Func<TEntity, TResult>> expression)
        {
            return new SetUpImpl<TEntity,TResult>(expression);
        }

    }
}
